# Copyright (c) 2013, yuxinyong and contributors
# For license information, please see license.txt

import frappe
from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport

def execute(filters=None):
	args = {
		"party_type": "Customer",
		"naming_by": ["Selling Settings", "cust_master_name"],
	}
	return MyReceivablePayableReport(filters).run(args)

class MyReceivablePayableReport(ReceivablePayableReport):
	def get_gl_entries(self):
		super(MyReceivablePayableReport, self).get_gl_entries()
		doctype_docs_map = {}
		for gle in self.gl_entries:
			docs = doctype_docs_map.setdefault(gle.voucher_type, [])
			docs.append(gle)
		gl_entries = []

		for (doctype, docs) in doctype_docs_map.items():
			allowed_docs = frappe.get_list(doctype, pluck='name')
			gl_entries.extend([gle for gle in docs if gle.voucher_no in allowed_docs])
			
		self.gl_entries = gl_entries